package com.linkoog.devtools.intellij.ui.table.column_info.provider.getter;

import com.linkoog.devtools.intellij.ui.table.TableRowData;
import com.linkoog.devtools.intellij.ui.table.column_info.provider.TableCellValueGetterProvider;

import java.lang.reflect.Method;

public class MethodTableCellValueGetterProvider<T extends TableRowData> implements TableCellValueGetterProvider<T> {

    private final String methodName;

    public MethodTableCellValueGetterProvider(String methodName) {
        this.methodName = methodName;
    }

    public Object valueOf(T itemInfo) {
        try {
            Method method =  itemInfo.getClass().getDeclaredMethod(methodName);
            return method.invoke(itemInfo);
        } catch (Exception ignored) {
        }
        return null;
    }
}
